package message.types.stringstring;

import java.io.IOException;

import message.visitor.MessageVisitor;
import network.e2e.FrameReader;
import stalker.Stalker;

public class LoginFailedAnswer extends StringStringMessage {

  /**
   * Creates a login request for the name
   */
  public LoginFailedAnswer(Stalker client, Stalker destination, String name, String reason) {
    super(client, destination, name, reason);
  }
  
  /**
   * Retrieves this message over the net
   * @throws IOException 
   */
  public LoginFailedAnswer(Stalker client, Stalker destination, FrameReader reader) throws IOException {
    super(client, destination, reader);
  }
  
  public String getName() {
    return getFirstString();
  }
  
  public String getReason() {
    return getSecondString();
  }
  
  @Override
  public <T> T accept(MessageVisitor<T> visitor) {
    return visitor.visit(this);
  }

  @Override
  public boolean equals(Object obj) {
    if (!(obj instanceof LoginFailedAnswer)) {
      return false;
    }
    return super.contentEquals(obj);
  }

  @Override
  public String toString() {
    return "LoginRequest with username : " + getName() + " failed because " + getReason();
  }

}
